package com.lhz.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lhz.services.DingdanService;

@Controller
@RequestMapping("/dingdan")//订单界面
public class DingdanControll {

	
	@Autowired
	private DingdanService service;
	
	
	
	
	/**
	 * 订单管理界面
	 * @return
	 */
	@RequestMapping( value="/dingdanManager")
	public ModelAndView dingdanManager(
			@RequestParam(name="pageNow",defaultValue="1",required=false)int pageNow,
			@RequestParam(name="pageSize",defaultValue="10",required=false)int pageSize,
			@RequestParam(name="dingdanId",defaultValue="")String dingdanId) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> info = service.dindingdanManager(pageNow,pageSize,dingdanId);
		mv.addObject("map", info);
		mv.setViewName("DingDanManager");
		return mv;
		
	}
	
	
	/**
	 * 订单详解界面
	 * @return
	 */
	@RequestMapping(value="/dingdandatashow")
	public ModelAndView dingdandatashow(String dingdan) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> info = service.dingdandatashow(dingdan);
		mv.addObject("map", info);
		System.err.println("BBBBBBBBBBBBBBBBBBB："+mv);
		mv.setViewName("DingDanDetailShow");
		return mv;
		
	}
	
	@RequestMapping(value="/DingDanServlet",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> DingDanServlet(Integer dingdanDT_id,String dingdanId){
		return service.updatetuicai(dingdanDT_id,dingdanId);
	}
	
	
	
	
	/**
	 * 修改掉用户完成状态和取消订单
	 * @param dingdanId
	 * @param status
	 * @return
	 */
	@RequestMapping(value="/updatecompletion",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> updatecompletion(String dingdanId,Integer status){
		return service.updatecompletion(dingdanId, status);
	}
	
	/**
	 * 订单界面状态索引
	 * @param status
	 * @return
	 */
	@RequestMapping(value="/searchBySelectInfo")
	public ModelAndView searchBySelectInfo(
			@RequestParam(name="pageNow",defaultValue="1",required=false)int pageNow,
			@RequestParam(name="pageSize",defaultValue="10",required=false)int pageSize,
			Integer status) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> info = service.searchBySelectInfo(pageNow,pageSize,status);
		//如果没有查到相关信息的话给他显示一个没有找到信息页面
		mv.addObject("map", info);
		mv.setViewName("DingDanManager");
		return mv;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
